package cn.ac.iscas.chinesesegmentme;

public class Token {
	public static final String Begin = "B"; 
	public static final String Middle = "M"; 
	public static final String End = "E";
	public static final String Single = "S"; 
	public String content;
	public String tag;

	public double[] predict = null;
	
	public Token(String content, String tag){
		this.content = content;
		this.tag = tag;
	}
	
	public Token(String content, double[] ocs){
		this.content = content;
		this.predict = ocs;
	}
	
	public String toString(){
		return (content + "[" + tag + "]");
	}
	//B[0.0305]  E[0.2242]  S[0.7453]  M[0.0000]
	public String getMostPossibleTag(){
		int maxi = 0;
		for (int i = 1; i < predict.length; i++){
			if (predict[i] > predict[maxi]) maxi = i;
		}
		switch (maxi){
		case 0:
			return Begin;
		case 1:
			return End;
		case 2:
			return Single;
		case 3:
			return Middle;
		}
		return null;
	}
	
	public double getMaxP(){
		int maxi = 0;
		for (int i = 1; i < predict.length; i++){
			if (predict[i] > predict[maxi]) maxi = i;
		}
		return predict[maxi];
	}
	
	public void setTag(int index){
		switch (index){
		case 0:
			tag =  Begin;
			break;
		case 1:
			tag =  End;
			break;
		case 2:
			tag =  Single;
			break;
		case 3:
			tag =  Middle;
			break;
		}		
	}
}
